package com.itbour.service.yjx.trade.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.common.util.StringUtils;
import com.itbour.dto.yjx.trade.YjxFeedbackFromDto;
import com.itbour.service.yjx.trade.YjxFeedbackFromService;
import com.itbour.dao.yjx.trade.YjxFeedbackInfoDao;


public class YjxFeedbackFromServiceImpl implements YjxFeedbackFromService {

	private YjxFeedbackInfoDao yjxFeedbackInfoDao;
	
	public YjxFeedbackInfoDao getYjxFeedbackInfoDao() {
		return yjxFeedbackInfoDao;
	}

	public void setYjxFeedbackInfoDao(YjxFeedbackInfoDao yjxFeedbackInfoDao) {
		this.yjxFeedbackInfoDao = yjxFeedbackInfoDao;
	}

	// 用户反馈
	@Override
	public Page feedbackPgQuery(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		try {
			Page result = null;
			
			// 实际起始位置
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = yjxFeedbackInfoDao.selectFeedbackCnt(param);
			
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<YjxFeedbackFromDto> data = yjxFeedbackInfoDao.selectFeedbackInfo(param);

			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			
		}
	}

	@Override
	public List<YjxFeedbackFromDto> selectFeedbackInfo(Map<String, Object> param) {
		return yjxFeedbackInfoDao.selectFeedbackInfo(param);
	}
	// 删除用户反馈
	@Override
	public void delFeedback(String delIds) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("ids", StringUtils.listToString2(StringUtils.stringToList2(delIds)));
		yjxFeedbackInfoDao.deleteFeedbackInfoLogic(param);
	}
	// 更新用户反馈
	@Override
	public void updFeedback(Map<String, Object> param) {
		yjxFeedbackInfoDao.updateFeedbackInfoById(param);
	}
	// 获取反馈来源
	@Override
	public List<YjxFeedbackFromDto> getFeedbackFrom4Combo(
			Map<String, Object> param) {
		return yjxFeedbackInfoDao.selectFeedbackFromInfo(param);
	}
}
